package ATM.gui;

import java.rmi.AccessException;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import ATM.data.Accounts;
import ATM.data.KeyValue;

public class DeleteAccount extends JPanel {

	Screen screen;
	private JLabel lblAccount;
	private JComboBox<KeyValue> accountList;
	private JButton btnDelete;
	private JButton btnExit;
	private ArrayList<Accounts> accounts = null;

	public DeleteAccount(Screen screen) {
		this.screen = screen;
		setLayout(null);

		lblAccount = new JLabel("Account:");
		lblAccount.setBounds(175, 141, 60, 14);
		add(lblAccount);

		accountList = new JComboBox<KeyValue>();
		accountList.setBounds(275, 141, 200, 20);
		add(accountList);

		btnDelete = new JButton("Delete");
		btnDelete.setBounds(515, 350, 89, 23);
		add(btnDelete);
		btnDelete.setActionCommand("DeleteAccount");
		btnDelete.addActionListener(screen.getAdminaL());

		btnExit = new JButton("Exit");
		btnExit.setBounds(515, 375, 89, 23);
		add(btnExit);
		btnExit.setActionCommand("ViewCustomer");
		btnExit.addActionListener(screen.getAdminaL());

		JLabel image = (new JLabel(screen.getVariables().getImage1()));
		image.setBounds(0, 0, 640, 480);
		add(image);

	}

	public void setAccounts(ArrayList<Accounts> accountsList) {
		accounts = accountsList;
		if (accounts != null) {
			accountList.removeAllItems();
			for (Accounts item : accounts)
				accountList.addItem(new KeyValue("" + item.getAccountID()
						+ ". " + item.getType(), "" + item.getAccountID()));
			btnDelete.setEnabled(false);
		}
		if (!accountsList.isEmpty())
			btnDelete.setEnabled(true);

	}

	public JComboBox<KeyValue> getAccounts() {
		return accountList;
	}

}
